import 'package:flutter/material.dart';

class FadeRoute extends PageRoute{
  FadeRoute({
    @required this.builder,
    this.transitionDuration = const Duration(milliseconds: 300),
    this.opaque = true,
    this.barrierDismissible = false,
    this.barrierColor,
    this.barrierLabel,
    this.maintainState = true,
});

  final WidgetBuilder builder;

  @override
  final Duration transitionDuration;

  @override
  final bool opaque;

  @override
  final bool barrierDismissible;

  @override
  final Color barrierColor;

  @override
  final String barrierLabel;

  @override
  final bool maintainState;

  @override
  Widget buildPage(BuildContext context, Animation<double> animation,
      Animation<double> secondaryAnimation) => builder(context);

  @override
  Widget buildTransitions(BuildContext context, Animation<double> animation,
      Animation<double> secondaryAnimation, Widget child) {
    // TODO: implement buildTransitions
    return FadeTransition(opacity: animation,child: builder(context),);
  }

}

class SelfRouteAnimationApp extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: Text("navigation"),),
        body:Column(
          children: <Widget>[
            RaisedButton(child: Text("push"),
                onPressed: ()=>Navigator.push(context, FadeRoute(builder: (context){
                  return PageB1();
                }))),
          ],
        ),
      ),
    );
  }
}

class PageB1 extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return
      Scaffold(
        appBar: AppBar(title: Text("navigation"),),
        body: Center(
          child: RaisedButton(child: Text("back"),
              onPressed: ()=>Navigator.of(context).pop()),
        ),
    );
  }
}


